﻿using Autofac;
using Autofac.Extras.DynamicProxy;
using System.Reflection;
using Wenyu.Framework.AutofacAOP.AOPExtend;
using Wenyu.Framework.BusinessServices;
using Wenyu.Framework.IBusinessServices;
using Wenyu.Framework.WebCore.ToolServices;

namespace Wenyu.Framework.WebApi.Utils.AutofacExtend
{
    public class WebApiAutofacModule : Autofac.Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            // 批量注册服务
            Assembly interfaces = Assembly.Load("Wenyu.Framework.IBusinessServices");
            Assembly services = Assembly.Load("Wenyu.Framework.BusinessServices");
            builder.RegisterAssemblyTypes(interfaces, services).AsImplementedInterfaces();

            // 注册服务
            //builder.RegisterType<TodayTestService>();
            //builder.RegisterType<UserService>().As<IUserService>();
            builder.RegisterType<JwtToolService>();

            // 支持Aop
            builder.RegisterType<CustomLogInterceptor>();
                
            builder.RegisterType<TestService>().As<ITestService>()
                //.EnableInterfaceInterceptors(); //nuget:Autofac.Extras.DynamicProxy
                .EnableClassInterceptors(); //nuget:Autofac.Extras.DynamicProxy

        }
    }
}
